import datetime
import time
# 获取前1天或N天的日期，beforeOfDay=1：前1天；beforeOfDay=N：前N天

# def getdate(self,beforeOfDay):
# beforeOfDay = 3
# today = datetime.datetime.now()
# # 计算偏移量
# offset = datetime.timedelta(days=-beforeOfDay)
# datetime.timedelta(s)
# # 获取想要的日期的时间
# re_date = (today + offset).strftime('%Y-%m-%d')
# print(re_date)
# time_value = time.strftime("%Y年%m月%d日".encode('unicode_escape').decode('utf8'), time.localtime(time.time())
#                            ).encode('utf-8').decode('unicode_escape')
def data_select(days=7):
    today = datetime.datetime.now()
    offset = datetime.timedelta(days=days)
    re_date = (today + offset).strftime("%Y年%m月%d日".encode("unicode_escape").decode("utf8")).encode('utf-8').decode('unicode_escape')
    print(re_date)
    return re_date

data_select(-4)
# 获取前一周的所有日期(weeks=1)，获取前N周的所有日期(weeks=N)
# def getBeforeWeekDays(self,weeks=1):
#     # 0,1,2,3,4,5,6,分别对应周一到周日
#     week = datetime.datetime.now().weekday()
#     days_list = []
#     start = 7 * weeks +  week
#     end = week
#     for index in range(start, end, -1):
#         day =self.getdate(index) print(day)
# #测试
# getBeforeWeekDays(1)